home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 34 / Amiga Format CD34 (1998-11-20)(Future Publishing)(GB)[!][Christmas issue].iso / -seriously_amiga- / programming / c / viewperf5.1 / viewperf / envaos.c < prev    next >
C/C++ Source or Header  |  1998-10-01  |  33KB  |  1,058 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4. #include <errno.h>
  5. #include <time.h>
  6. #include <math.h>
  7. #include "Env.h"
  8. #include <malloc.h>
  9. #include <gl/glaux.h>
  10. #include "viewperf.h"
  11.  
  12. static char *GetShortVendorName(char *input);
  13. static int GetHostMemorySize(void);
  14. static char *GetHostVendor(void);
  15. static char *GetHostModel(void);
  16. static char *GetHostCPU(void);
  17. static char *GetHostOperatingSystem(void);
  18. static char *GetHostOperatingSystemRelease(void);
  19. static char *GetHostName(void);
  20. static char *GetOpenGLClientVendor(void);
  21. static char *GetOpenGLClientVersion(void);
  22. static char *GetOpenGLClientExtensions(void);
  23. static char *GetHostCPUCount(void);
  24. static char *GetHostPrimaryCacheSize(void);
  25. static char *GetHostSecondaryCacheSize(void);
  26. static char *GetWindowSystem(void);
  27. static char *GetDriverVersion(void);
  28.  
  29.  
  30. /******************************************************************************
  31.  *
  32.  * StringSearch - search for pattern in string
  33.  *
  34.  * Description:
  35.  *  StringSearch returns a pointer to the first occurance of pattern found in
  36.  *  the subject or NULL if the pattern is not found. It implements the
  37.  *  Knuth-Morris-Pratt pattern matching algorithm. If m is the length of the
  38.  *  pattern and n is the length of the subject, the complexity of the KMP
  39.  *  algorithm is (m+n), much better than the (m*n) complexity of the naive
  40.  *  nested loop algorithm. - John Dennis
  41.  *
  42.  * Returns:
  43.  *  pointer to the first occurance of pattern found the subject or NULL
  44.  *
  45.  * Side Effects:
  46.  *  None
  47.  *
  48.  * Errors:
  49.  *  None
  50.  *
  51.  * Revision History:
  52.  *  Revision 0: Author: John R. Dennis Date: Thu Aug  4 15:49:59 1994
  53.  *    Initial Release
  54.  *
  55.  *****************************************************************************/
  56. char *
  57. StringSearch(char *subject, char *pattern)
  58. {
  59. #define MAX_FLINK (256)
  60.   int *flink, *dynamicFlink = NULL, staticFlink[MAX_FLINK];
  61.   int patternLen = strlen(pattern);
  62.   int subjectLen = strlen(subject);
  63.   int found = 0;
  64.   int i,j;
  65.  
  66.   if (patternLen > MAX_FLINK) {      /* -1 for NULL terminator */
  67.     dynamicFlink = malloc(patternLen * sizeof(int));
  68.     if (dynamicFlink == NULL) {
  69.       fprintf(stderr, "malloc failure, line %d, file: %s, exiting...\n",
  70.           __LINE__, __FILE__);
  71.       exit(1);
  72.     }
  73.     flink = dynamicFlink;
  74.   }
  75.   else {
  76.     flink = staticFlink;
  77.   }
  78.  
  79.  
  80.   /* Step 1: Constuct Flowchart */
  81.   flink[0] = -1;               /* -1 == read next char */
  82.   for(i = 1; i < patternLen; i++) {
  83.     j = flink[i-1];
  84.     while((j >= 0) && (pattern[j] != pattern[i-1])) {
  85.       j = flink[j];
  86.     }
  87.     flink[i] = j+1;
  88.   }
  89.  
  90.   /* Step 2: Scan Algorithm */
  91.   for (i = j = 0; i < subjectLen; i++, j++) {
  92.     while((j >= 0) && (pattern[j] != subject[i])) {
  93.       j = flink[j];
  94.     }
  95.     if (j == patternLen-1) {
  96.       found = 1;
  97.       goto exit;
  98.     }
  99.   }
  100.  
  101.  exit:
  102.   if (dynamicFlink != NULL) free(dynamicFlink);
  103.   if (!found)
  104.     return(NULL);
  105.   else
  106.     return(&subject[i-patternLen+1]);
  107. #undef MAX_FLINK
  108. }
  109.  
  110.  
  111. /******************************************************************************
  112.  *
  113.  * GetShortVendorName - return short vendor string
  114.  *
  115.  * Description:
  116.  *  some vendor strings are verbose. This function will return a shortest
  117.  *  vendor name it can given an arbitrary vendor string. The returned string
  118.  *  is allocated with malloc, it should be freed when no longer in use. The
  119.  *  input string is not freed or modified by this function.
  120.  *
  121.  * Returns:
  122.  *  pointer to allocated string
  123.  *
  124.  * Side Effects:
  125.  *  string allocation, string should be freed when no longer needed.
  126.  *
  127.  * Errors:
  128.  *  no errors, if function fails the string "unknown" is returned
  129.  *
  130.  * Revision History:
  131.  *  Revision 0: Author: John R. Dennis Date: Mon Aug  8 16:30:53 1994
  132.  *    Initial Release
  133.  *
  134.  *****************************************************************************/
  135. static char *
  136. GetShortVendorName(char *input)
  137. {
  138.   int i;
  139.   char *s1 = NULL;              /* s1 is temp work string */
  140.   char *s2 = NULL;              /* s2 is string to return */
  141.  
  142.   /* duplicate input string so that we can modify it */
  143.   s1 = strdup(input);
  144.   /* upcase string */
  145.   for (i = 0; s1[i]; i++)
  146.     if (islower(s1[i])) s1[i] = toupper(s1[i]);
  147.  
  148.   /* return a short name if possible, some vendor names are verbose */
  149.   if (StringSearch(s1, "DEC") ||
  150.       StringSearch(s1, "DECWINDOWS") ||
  151.       StringSearch(s1, "Digital Equipment Corporation") ||
  152.       StringSearch(s1, "DigitalEquipmentCorporation"))
  153.     s2 = strdup("DEC");
  154.   else if (StringSearch(s1, "SGI") ||
  155.        StringSearch(s1, "SILCON GRAPHICS"))
  156.     s2 = strdup("SGI");
  157.   else if (StringSearch(s1, "IBM") ||
  158.        StringSearch(s1, "INTERNATIONAL BUSINESS MACHINES"))
  159.     s2 = strdup("IBM");
  160.   else
  161.     s2 = strdup(s1);
  162.  
  163.   free(s1);
  164.   return(s2);
  165. }
  166.  
  167.  
  168. /******************************************************************************
  169.  *
  170.  * GetHostMemorySize - Return kilobytes of memory installed on host platform
  171.  *
  172.  * Description:
  173.  *  Returns the number of kilobytes of memory installed on host platform
  174.  *
  175.  * Returns:
  176.  *  kilobytes of host platform memory
  177.  *
  178.  * Side Effects:
  179.  *  None
  180.  *
  181.  * Errors:
  182.  *  return 0 if unable to determine memory configuration
  183.  *
  184.  * Revision History:
  185.  *  Revision 0: Author: John R. Dennis Date: Thu Aug  4 15:55:19 1994
  186.  *    Initial Release
  187.  *
  188.  *****************************************************************************/
  189. static int
  190. GetHostMemorySize(void)
  191. {
  192.   /* AvailMem */
  193.   return (24 * 1024 * 1024) / 1024;
  194. }
  195.  
  196.  
  197. /******************************************************************************
  198.  *
  199.  * GetHostVendor - return string naming the system vendor
  200.  *
  201.  * Description:
  202.  *  return the name of the system vendor as a string. This is to identify
  203.  *  manufacturer of the system. The string is allocated with malloc, it should
  204.  *  be freed when no longer in use.
  205.  *
  206.  * Returns:
  207.  *  pointer to allocated string
  208.  *
  209.  * Side Effects:
  210.  *  string allocation, string should be freed when no longer needed.
  211.  *
  212.  * Errors:
  213.  *  no errors, if function fails the string "unknown" is returned
  214.  *
  215.  * Revision History:
  216.  *  Revision 0: Author: John R. Dennis Date: Mon Aug  8 16:30:53 1994
  217.  *    Initial Release
  218.  *
  219.  *****************************************************************************/
  220. static char *
  221. GetHostVendor(void)
  222. {
  223.   /* See if it's a DEC system */
  224.   char *hostModel;
  225.  
  226.   hostModel = GetHostModel();
  227.   if ( strstr(hostModel,"DEC") == hostModel)
  228.   {
  229.     free(hostModel);
  230.     return(strdup("DEC"));
  231.   }
  232.   else
  233.   {
  234.     free(hostModel);
  235.     return(strdup("unknown"));
  236.   }
  237. }
  238.  
  239.  
  240. /******************************************************************************
  241.  *
  242.  * GetHostModel - return string naming the host model
  243.  *
  244.  * Description:
  245.  * return string identifying the host platform's model designation. The string
  246.  * is allocated with malloc, it should be freed when no longer in use.
  247.  *
  248.  * Returns:
  249.  *  pointer to allocated string
  250.  *
  251.  * Side Effects:
  252.  *  string allocation, string should be freed when no longer needed.
  253.  *
  254.  * Errors:
  255.  *  no errors, if function fails the string "unknown" is returned
  256.  *
  257.  * Revision History:
  258.  *  Revision 0: Author: John R. Dennis Date: Mon Aug  8 16:30:53 1994
  259.  *    Initial Release
  260.  *
  261.  *****************************************************************************/
  262. static char *
  263. GetHostModel(void)
  264. {
  265.   return strdup("AmigaOS");
  266. }
  267.  
  268.  
  269. /******************************************************************************
  270.  *
  271.  * GetHostCPU - return string naming the host CPU
  272.  *
  273.  * Description:
  274.  * return string identifying the host platform's CPU. The string
  275.  * is allocated with malloc, it should be freed when no longer in use.
  276.  *
  277.  * Returns:
  278.  *  pointer to allocated string
  279.  *
  280.  * Side Effects:
  281.  *  string allocation, string should be freed when no longer needed.
  282.  *
  283.  * Errors:
  284.  *  no errors, if function fails the string "unknown" is returned
  285.  *
  286.  * Revision History:
  287.  *  Revision 0: Author: John R. Dennis Date: Mon Aug  8 16:30:53 1994
  288.  *    Initial Release
  289.  *
  290.  *****************************************************************************/
  291. static char *
  292. GetHostCPU(void)
  293. {
  294.   return strdup("Motorola MC68030 (30MHz), MC68882 (30MHz)");
  295. }
  296.  
  297.  
  298. /******************************************************************************
  299.  *
  300.  * GetHostCPUCount - return string indica